<template>
  <div class="parent-child-demo">
    <!-- 父组件 -->
    <div class="parent-component">
      <h4>父组件</h4>
      <div class="component-content">
        <p>子组件传来的消息: {{ messageFromChild }}</p>
        <el-input v-model="messageToChild" placeholder="输入消息发送给子组件">
          <template #append>
            <el-button @click="sendToChild">发送</el-button>
          </template>
        </el-input>
      </div>
    </div>

    <!-- 子组件 -->
    <child-component 
      :message="messageToChild"
      @reply="handleChildReply" />
  </div>
</template>

<script>
import ChildComponent from './ChildComponent.vue'

export default {
  name: 'ParentChildDemo',
  components: { ChildComponent },
  
  data() {
    return {
      messageToChild: '',
      messageFromChild: ''
    }
  },

  methods: {
    sendToChild() {
      this.messageToChild = this.messageToChild.trim()
      if (!this.messageToChild) return
    },

    handleChildReply(message) {
      this.messageFromChild = message
    }
  }
}
</script>

<style scoped>
.parent-child-demo {
  border: 1px solid #dcdfe6;
  border-radius: 4px;
  padding: 15px;
}

.parent-component {
  margin-bottom: 15px;
}

.component-content {
  padding: 10px;
  background: #fff;
  border-radius: 4px;
}

h4 {
  margin: 0 0 10px 0;
  color: #606266;
}
</style> 